{extend name="public/base"/}
{block name="body"}
<style type="text/css">
	.attrs{margin-top:5px;}
	.attrname{width:100px;border:solid 1px #ddd;height:31px;font-size:14px;padding-left:4px;}
	.attrval{width:40%;border:solid 1px #ddd;height:31px;font-size:14px;padding-left:4px;}
</style>
<title>编辑轮播图</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add">
		<input type="hidden" class="input-text" value="{$data.id}" id="id" name="id">
		
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">本地/第三方：</label>
			<div class="formControls col-xs-8 col-sm-9 skin-minimal">
				<div class="radio-box">
					<input class="change1" name="type" type="radio" id="status-1" value="1" {if $data.type==1}checked{/if}>
					<label class="change1" for="status-1">本地</label>
				</div>
				<div class="radio-box">
					<input class="change2" name="type" type="radio" id="status-2" value="2" {if $data.type==2}checked{/if}>
					<label class="change3" for="status-2">第三方</label>
				</div>
			</div>
		</div>
		<div class="row cl tmdimg">
			<label class="form-label col-xs-3 col-sm-2">标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$data.title}" id="title" name="title">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">简介：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$data.intro}" id="intro" name="intro">
			</div>
		</div>
		<div class="row cl tmdimg">
			<label class="form-label col-xs-3 col-sm-2">图片：</label>
			<div class="formControls col-xs-8 col-sm-9">
                <div style="position:relative;" id="drop_area"></div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2 locals"></label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$data.url}" id="url" name="url">
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input id="submit" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
<script type="text/javascript" src="/static/js/upload.js"></script>
<script type="text/javascript">
var imgpz;
var dragImgUpload = new DragImgUpload("#drop_area",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var file = files[0];
	        var formData = new FormData();
	        formData.append("file",file);
	        $.ajax({
	              type: 'POST',
	              url: "{:url('uploadtmd')}",
	              data:formData,
	              contentType: false, /*不可缺*/
	              processData: false, /*不可缺*/
	              success: function(response){
	                if(response.code==200){
	                  imgpz=response.photo
	                }else{
	                  alert(response.msg);
	                }
	              },
	              error: function(err){

	              }
	        })
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
$(function(){
	if('{$data.type}'==1){
		$(".locals").text('产品id：');
		$(".tmdimg").hide();
	}else if('{$data.type}'==2){
		$(".locals").text('第三方链接');
		$(".tmdimg").show();
	}
   	var change1=$(".change1")
   	var change2=$(".change2")
   	var menu_li=$(".radio-box")
   	change1.click(function(){
      	$(".tmdimg").hide();
		$(".locals").text('产品id：');
    })
   	change2.click(function(){
      	$(".tmdimg").show();
		$(".locals").text('第三方链接');
    })
	$('#drop_area div img').attr('src','{$data.img}');
	$('#drop_area div img').attr('onerror',"javascript:this.src='/static/img/upload.png'");
	if($("#drop_area div img").attr('src')=='/static/img/upload.png'){
		imgpz='';
	}else{
		imgpz= $("#drop_area div img").attr('src');
	}
});
$("#submit").click(function() {
	layer.load(1, {
	  shade: [0.1,'#fff'] //0.1透明度的白色背景
	});
	var id=$("input[name=id]").val();
	var url=$("input[name=url]").val();
	var intro=$("input[name=intro]").val();
	var title=$("input[name=title]").val();
	var type=$("input[name='type']:checked").val();
    $.ajax({
	    type: 'POST',
	    url: "{:url('banner_edit')}",
	    data: {id:id,url:url,type:type,img:imgpz,intro:intro,title:title},
	    success: function(resdata){
	        if(resdata.code==200){
				layer.msg(resdata.msg,{icon:1,time:1000});
				setTimeout("parent.location.reload()",1000);
	        }else{
				layer.msg(resdata.msg,{icon:2,time:3000});
	        }
	    },
	    error: function(){
			layer.msg('数据保存失败',{icon:2,time:3000});
	    }
	})
})
</script> 
{/block}